#!/usr/local/bin/python

# __    _____ _____ _____    ___     ___ 
#|  |  |  _  |     |   __|  |_  |   |   |
#|  |__|     | | | |__   |   _| |_ _| | |
#|_____|__|__|_|_|_|_____|  |_____|_|___|

# Script to return average call duration
# Author: Carl Javier 4088697
# Date: 21 September 2008

#used to see if any mobile calls were made
# from call records

import sys, os


cut = "/usr/bin/cut"
grep = "/usr/bin/grep"
jailpwd=""
callrecord="/var/log/asterisk/cdr-csv/Master.csv"
#outbound VSP name in sip.conf
vsp="pennytel"

#the 9th column represents the number dialed

#command = cut+ " -d \",\" -f 9 " +jailpwd+ callrecord + " |"+grep +" "+ vsp +"|"+cut + " -d\"/\" -f 2 |"+ cut + " -d \"@\" -f 1"

# the 3th column in call records represents the number dialed
#Only get the last 100 calls
command = cut+ " -d \",\" -f 3 " +jailpwd+ callrecord + " |" + cut + " -d \\\" -f 2 | tail -100"

#print command
fileOpen = os.popen(command,'r')

counter = 0
for x in fileOpen:
	
	#print x[:2]
	if (x[:3]=='004' and len(x)==12): #use to compare to 11 to include \n character
		#print x[:len(x)-1] #-1 refers to removing the \n character
		counter+=1



print str(counter)

fileOpen.close()

